;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Report.DealerPlanDetail", [])
        .controller("DealerPlanDetailCtrl", ["$scope", "$state", "ybWidget", "ybHttp", "MESG_TYPE", "$filter", "$timeout", "UserContextService", "$stateParams", function ($scope, $state, ybWidget, ybHttp, MESG_TYPE, $filter, $timeout, UserContextService, $stateParams) {
            $scope.markInfo = {
                curRow: -1
            };

            $scope.pageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };

            $scope.exportParam = {
                allUrl: ybHttp.RequestUrl("device", "/dealerPlanCrm/exportAll")
            };

            $scope.toolbarConfig = {
                showAdvanceSearch: false,
                showColConfig: false,
            };
            $scope.switchToolbar = function (toolbar) {
                if (!!$scope.toolbarConfig["show" + toolbar]) {
                    $scope.toolbarConfig["show" + toolbar] = false;
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig["show" + toolbar] = true;
                    });
                }
            };

            $scope.condition = {};
            $scope.dataList = [];

            $scope.tbConf = {
                scrollWidth: 3500,
                tableCol: [
                    {
                        name: "大区",
                        width: 100,
                        dataField: "belongsRegion",
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "储备方-经销商",
                        width: 150,
                        dataField: "reserveStationName",
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "零件编号",
                        width: 120,
                        dataField: "newProductCode",
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "零件中文名",
                        width: 150,
                        dataField: "newProductName",
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "是否直投",
                        width: 100,
                        dataField: "isDirectCastShow",
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "CRM—储备数量",
                        width: 120,
                        dataField: "stockCnt",
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "经销商在途零件数量B",
                        dataField: "onWayCnt",
                        width: 160,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "PMS—经销商库存数量",
                        dataField: "customerCnt",
                        width: 160,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "计划储备数量1",
                        dataField: "planReserveCnt",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "PMS库存占用数量",
                        dataField: "customerOccupyCnt",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "月度储备数量",
                        dataField: "monthlyReserveCnt",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "9024库占用数量",
                        dataField: "nineOccupyCnt",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "采购单价",
                        dataField: "purchaseCost",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "CRM金额",
                        dataField: "stockCost",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "经销商在途零件金额",
                        dataField: "onWayCost",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "PMS库存金额",
                        dataField: "pmsStockCost",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "PMS库存占用金额",
                        dataField: "pmsStockOccupyCost",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "PMS-9024占用金额",
                        dataField: "pmsNineOccupyCost",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "月度储备金额",
                        dataField: "monthlyReserveCost",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "机型",
                        dataField: "newProductModelNames",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                    },
                ]
            };

            $scope.reset = function () {
                $scope.condition = {};
            };

            $scope.search = function (curpage) {
                getDataList(curpage);
            };

            $scope.selectRow = function (index) {
                $scope.markInfo.curRow = index;
            };

            function getDataList(curPage) {
                $scope.markInfo.curRow = -1;
                if (!!curPage) {
                    $scope.pageInfo.curPage = curPage;
                }

                var service = "device";
                var reqUrl = "/dealerPlanCrm/detailReport";
                var param = {
                    pageNum: $scope.pageInfo.curPage,
                    pageSize: $scope.pageInfo.pageSize,
                    filters: angular.copy($scope.condition)
                };
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    angular.forEach(resp.value.list, function (item) {
                        item.isDirectCastShow = $filter("TrueOrFalse")(item.isDirectCast);
                    });
                    $scope.pageInfo.totalRows = resp.value.total;
                    $scope.pageInfo.totalPages = resp.value.pages;
                    $scope.dataList = resp.value.list;
                });
            }

            (function () {
                getDataList();
            })();
        }])
    ;
})(window, window.angular);